<?php

/**
 * This is the model class for table "moja_baza.uzytkownik".
 *
 * The followings are the available columns in table 'moja_baza.uzytkownik':
 * @property integer $idUzytkownika
 * @property integer $idOsoby
 * @property string $login
 * @property string $haslo
 * @property string $email
 * @property integer $liczba_ostrzezen
 *
 * The followings are the available model relations:
 * @property Rezerwacja[] $rezerwacjas
 * @property Osoba $idOsoby0
 */
class Uzytkownik extends CActiveRecord
{
	public $email2;
        public $haslo2;
        /**
	 * Returns the static model of the specified AR class.
	 * @return Uzytkownik the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'moja_baza.uzytkownik';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('login, haslo', 'required'),
                        array('haslo2', 'required', 'on'=>'validEmail'),
			array('idUzytkownika, idOsoby, liczba_ostrzezen', 'numerical', 'integerOnly'=>true),
			array('login', 'length', 'max'=>20),
			array('haslo', 'length', 'min'=>8, 'max'=>32),
			array('email', 'length', 'max'=>45),
                        array('email, email2', 'email'),
                        array('email2', 'compare', 'compareAttribute'=>'email', 'on'=>'validEmail'),
                        array('haslo2', 'compare', 'compareAttribute'=>'haslo', 'on'=>'validEmail'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('idUzytkownika, idOsoby, login, haslo, email, liczba_ostrzezen', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'rezerwacje' => array(self::HAS_MANY, 'Rezerwacja', 'idUzytkownika'),
			'osoba' => array(self::BELONGS_TO, 'Osoba', 'idOsoby'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'idUzytkownika' => 'Id Uzytkownika',
			'idOsoby' => 'Id Osoby',
			'login' => 'Login',
			'haslo' => 'Hasło',
                        'haslo2' => 'Powtórz hasło',
			'email' => 'E-mail',
                        'email2' => 'Powtórz e-mail',
			'liczba_ostrzezen' => 'Liczba Ostrzeżeń',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('idUzytkownika',$this->idUzytkownika);
		$criteria->compare('idOsoby',$this->idOsoby);
		$criteria->compare('login',$this->login,true);
		$criteria->compare('haslo',$this->haslo,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('liczba_ostrzezen',$this->liczba_ostrzezen);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}